insert
    overwrite
    table jms_dm.dm_dev_repair_network_monitor_center_summary_dt
    partition
    (dt)
select scan_network_code
     , scan_network_name
     , date_time
     , sum(if(scan_type_code = '07', 1, 0)) as cen_wxin_num     --中心维修入库数
     , sum(if(scan_type_code = '34', 1, 0)) as cen_wxout_num    --中心维修出库数
     , sum(if(scan_type_code = '34' and next_type_code = '07' and is_repair_next = 1, 1,
              0))                           as net_wxin_num     --维修点已入库数
     , sum(if(scan_type_code = '34' and !(next_type_code = '07' and is_repair_next = 1), 1,
              0))                           as net_notwxin_num  --维修点未入库数
     , sum(if(scan_type_code = '08', 1, 0)) as cen_xfin_num     --中心修复入库数
     , sum(if(scan_type_code = '08' and before_type_code = '34' and is_repair_before = 1, 1,
              0))                           as net_wxout_num    --维修点已出库数
     , sum(if(scan_type_code = '08' and !(before_type_code = '34' and is_repair_before = 1), 1,
              0))                           as net_notwxout_num --维修点未出库数
     , dt
from jms_dm.dm_dev_repair_network_monitor_rfid_detail_dt
where dt <= '{{ execution_date | cst_ds }}'
  and dt >= date_add('{{ execution_date | cst_ds }}', -2)
  and type = 2
group by scan_network_code
       , scan_network_name
       , date_time
       , dt
    distribute by dt
;
